﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;

namespace WCFSelfTuoGuan
{
    public class ServiceHost<T> : ServiceHost
    {
        public ServiceHost():base(typeof(T))
        {

        }
        public bool EnableMetadataExchange
        {
            set
            {
                if(State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Host is already opened");
                }
                ServiceMetadataBehavior metadataBehavior = Description.Behaviors.Find<ServiceMetadataBehavior>();
                if(metadataBehavior is null)
                {
                    metadataBehavior = new ServiceMetadataBehavior();
                    Description.Behaviors.Add(metadataBehavior);
                }
                if(value is true)
                {
                    if (!HasMexEndpoint)
                    {
                        AddAllMexEndPoinds();
                    }
                }
            }
            get
            {
                ServiceMetadataBehavior serviceMetadata = Description.Behaviors.Find<ServiceMetadataBehavior>();
                if(serviceMetadata is null)
                {
                    return false;
                }
                else
                {
                    return serviceMetadata.HttpGetEnabled;
                }
            }
        }
        public bool HasMexEndpoint
        {
            get
            {
                Predicate<ServiceEndpoint> predicate = delegate (ServiceEndpoint point)
                {
                    return true;
                };
                return false;
                //return Collection.Exist(Description.Endpoints,mexEnd) 
            }
        }

        public void AddAllMexEndPoinds() { }
    }
}
